package com.shangxia.monomer.study.math.formula;

/**
 * @author zhouya38158
 * @Package com.shangxia.monomer.study.math
 * @date 2021/7/22 9:45
 */
public class PrimeNumber {
    /**
     * 判断 number 是否为素数
     * @param number
     * @return
     */
    public static boolean isPrime(int number) {
        if (number < 3) {
            return true;
        }

        // check if n is a multiple of 2
        if (number % 2 == 0) {
            return false;
        }

        // if not, then just check the odds
        for (int i = 3; i * i <= number; i += 2) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }
}
